# import xlrd
#
# table = xlrd.open_workbook('./resources/阿里巴巴2020年股票数据.xls')
#
# sheetnames = table.sheet_names()
#
# data = table.sheet_by_name(sheetnames[0])
#
# for row in range(data.nrows):
#     for col in range(data.ncols):
#         value = data.cell(row, col).value
#         # print(value)
#         if row > 0:
#             # 将第一列的日期数据进行格式化处理，处理成 年 月 日的形式
#             if col == 0:
#                 value = xlrd.xldate_as_tuple(value, 0)
#                 value = f"{value[0]}年{value[1]:>02d}月{value[2]:>02d}日"
#             else:
#                 # 其它列数据统一处理为两位数的小数位数
#                 value = f"{value:.2f}"
#         print(value, end='\t')
#     print()
#
#
# # 获取单元格值的数据类型
# # 0 - 空值    1 - 字符串     2 - 数字      3 - 日期      4 - 布尔      5 - 错误
# last_cell_type = data.cell_type(data.nrows -1 , data.ncols - 1)
# print(last_cell_type)
#
#
# # 获取第一行的值
# print(data.row_values(0))
#
#
#
#
#
# import xlwt
# import random
#
# # 创建工作簿对象
# wb = xlwt.Workbook()
# # 创建工作表对象
# sheet = wb.add_sheet("python-2106班级")
#
# # 定义学生姓名
# students_name = ["关羽", "张飞", "刘备", "吕布", "马超"]
# # 通过列表生成事生成成绩表  语文 数学 英语      二维列表
# scores = [[random.randrange(50, 101) for i in range(3)] for j in range(5)]
# print(scores)
#
# # 创建表头数据
# titles = ("姓名", "语文", "数学", "英语")
#
# # 设置表头数据的样式，颜色设置为红色
# header_style = xlwt.XFStyle()
# pattern = xlwt.Pattern()
# pattern.pattern = xlwt.Pattern.SOLID_PATTERN
# # 0-黑色  1-白色  2-红色  3-绿色    4-蓝色    5-粉色
#
# for index, title in enumerate(titles):
#     # 第一个参数表示行，第二个参数表示列，第三个参数表示内容，第四个参数表示样式
#     sheet.write(0, index, title)
#
# # 将学生的姓名和成绩写入到工作表中
# for row in range(len(scores)):
#     sheet.write(row+1, 0, students_name[row])
#     for col in range(len(scores[row])):
#         sheet.write(row+1, col+1, scores[row][col])
#
# # 保存数据到工作簿
# wb.save("考试成绩.xls")
#
#
#
#
#
#
# import openpyxl
# import datetime
#
# # 加载一个工作簿
# wb = openpyxl.load_workbook("./resources/阿里巴巴2020年股票数据.xlsx")
#
# print(wb.sheetnames)
#
# # 获取具体要操作的工作表
# sheet = wb.worksheets[0]
#
# # 获取工作表中单元格的范围
# print(sheet.dimensions)     # A1:G255
#
# # 获取行数和列数
# print(sheet.max_row, sheet.max_column)
#
# # 获取指定单元格的值
# print(sheet.cell(3, 3).value)
# print(sheet['C3'].value)
#
# # 获取多个单元格
# # print(sheet['A2', 'C5'])
#
# for row in range(2, sheet.max_row+1):
#     for col in 'ABCDEFG':
#         value = sheet[f'{col}{row}'].value
#         print(value, end='\t')
#     print()
#
#
#
#
#
#
# import openpyxl
# import random
#
# # 第一步：创建工作簿
# wb = openpyxl.Workbook()
# # 第二部：添加工作表
# sheet = wb.active
# sheet.title = "测试成绩"
#
# titles = ("姓名", "读书", "骑马", "射箭")
# # 行和列的索引全部从1开始
# for col_index, title in enumerate(titles):
#     sheet.cell(1, col_index+1, title)
#
# names = ("天偿", "圆寂", "支勋", "渣渣辉", "润邦")
# for row_index, name in enumerate(names):
#     sheet.cell(row_index+2, 1, name)
#     for col_index in range(2, 5):
#         sheet.cell(row_index+2, col_index, random.randrange(50, 101))
#
# # 最后保存工作簿
# wb.save("期末测试成绩.xlsx")
#
#
#
#
#
#
# from openpyxl import Workbook
# from openpyxl.chart import BarChart, Reference
#
# wb = Workbook(write_only=True)
# sheet = wb.create_sheet("手机销量统计")
#
# rows = [
#     ('类别', 'G战区', 'X战区'),
#     ('小米', 88, 76),
#     ('vivo', 68, 89),
#     ('oppo', 87, 59)
# ]
#
# # 向工作表中添加行
# for row in rows:
#     sheet.append(row)
#
# # 创建图表对象
# chart = BarChart()
# chart.type = 'col'
# chart.style = 10
#
# # 设置图表的标题
# chart.title = "手机销量统计"
# # 设计纵轴的标题
# chart.y_axis.title = '销量'
# # 设置横轴标题
# chart.x_axis.title = '类别'
#
#
# # 设置数据的范围
# data = Reference(sheet, min_col=2, min_row=1, max_row=5, max_col=3)
# # 设置分类的范围
# category = Reference(sheet, min_col=1, min_row=2, max_row=5)
#
# # 给图表添加数据
# chart.add_data(data, titles_from_data=True)
# # 给图表设置分类
# chart.set_categories(category)
# chart.shape = 4
# # 将图表插入到指定的单元格当中
# sheet.add_chart(chart, 'A10')
# wb.save("手机销量统计.xlsx")
#
#
#
#
#
#













